home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 16 / IOPROG_16.ISO / soft / macaxsdk / macsdk.hqx / ActiveX DR3 SDK / ActiveX SDK / Sample Containers / ActiveXApp / CActiveXApp.cpp / CActiveXApp.cpp
Encoding:
C/C++ Source or Header  |  1997-09-05  |  6.9 KB  |  262 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //    CActiveXApp.cpp                    ⌐1996-1997 Microsoft Corporation. All rights reserved.
  3. //                                    portions ⌐1995 Metrowerks Inc. All rights reserved.
  4. // =================================================================================
  5.  
  6. #include <LGrowZone.h>
  7. #include <LMenu.h>
  8. #include <LMenuBar.h>
  9. #include <LMouseTracker.h>
  10. #include <LString.h>
  11. #include <LWindow.h>
  12. #include <LTableView.h>
  13. #include <LHierarchyTable.h>
  14. #include <LGAColorSwatch.h>
  15. #include <LGASeparator.h>
  16. #include <PP_Messages.h>
  17. #include <PPobClasses.h>
  18. #include <UDesktop.h>
  19. #include <UDrawingState.h>
  20. #include <UMemoryMgr.h>
  21. #include <UReanimator.h>
  22. #include <URegistrar.h>
  23. #include <UTextTraits.h>
  24.  
  25. //    ÑActiveXÑ - begin ActiveX headers
  26. #include "ActiveXAPI.h"
  27.  
  28. #include "ActiveXAppConstants.h"
  29. #include "CActiveXInfo.h"
  30. #include "CActiveXTable.h"
  31. #include "CActiveXColorPane.h"
  32. #include "CActiveXDocument.h"
  33. #include "CActiveXView.h"
  34. #include "CActiveXAppView.h"
  35. #include "CActiveXShadowView.h"
  36. //#include "CActiveXPeriodical.h"
  37. #include "CActiveXApp.h"
  38. #include "CActiveXAppAttachment.h"
  39. //    ÑActiveXÑ - end ActiveX headers
  40.  
  41.  
  42. // =================================================================================
  43. //        Ñ Main Program
  44. // =================================================================================
  45.  
  46. void
  47. main( void )
  48. {
  49.     // Initialize the heap. Parameter is number
  50.     // of master handle blocks to allocate.
  51.     InitializeHeap( 4 );
  52.     
  53.     // Initialize the MacOS toolbox.
  54.     UQDGlobals::InitializeToolbox( &qd );
  55.  
  56.     // Install a GrowZone function to catch  low memory situations.
  57.     // Parameter is the size of the memory reserve in bytes.
  58.     new LGrowZone( 20000 );
  59.  
  60.     // Create the application object and run it.
  61.     CActiveXApp    theApp;
  62.     
  63.     theApp.Run();
  64. }
  65.  
  66.  
  67. // ---------------------------------------------------------------------------------
  68. //        Ñ CActiveXApp::CActiveXApp
  69. // ---------------------------------------------------------------------------------
  70. // Constructor
  71.  
  72. CActiveXApp::CActiveXApp()
  73. {
  74.     // Setup the throw and signal actions.
  75.     SetDebugThrow_( debugAction_Alert );
  76.     SetDebugSignal_( debugAction_Alert );
  77.  
  78.     // Register PowerPlant class creator functions.
  79.     RegisterAllPPClasses();
  80.  
  81.     // ÑActiveXÑ Register custom classes for the ActiveX pane types
  82.     URegistrar::RegisterClass( CActiveXAppView::class_ID, (ClassCreatorFunc) CActiveXAppView::CreateActiveXAppViewStream );
  83.     URegistrar::RegisterClass( CActiveXShadowView::class_ID, (ClassCreatorFunc) CActiveXShadowView::CreateActiveXShadowViewStream );
  84.  
  85.     // ************** ObjectDesc Table classes registration ************** //
  86.     
  87.     RegisterClass_(LGASeparator);
  88.     
  89.     // Register custom classes.
  90.     URegistrar::RegisterClass( CActiveXInfo::class_ID,
  91.         (ClassCreatorFunc) CActiveXInfo::CreateActiveXInfoStream );
  92.     URegistrar::RegisterClass( CActiveXColorPane::class_ID, (ClassCreatorFunc) CActiveXColorPane::CreateColorPaneStream );
  93.     URegistrar::RegisterClass( CActiveXTable::class_ID,
  94.         (ClassCreatorFunc) CActiveXTable::CreateActiveXTableStream );
  95.  
  96.     // ************** End ObjectDesc Table classes registration ************** //
  97.             
  98.     AddAttachment( new CActiveXAppAttachment() );
  99. }
  100.  
  101.  
  102. // ---------------------------------------------------------------------------------
  103. //        Ñ CActiveXApp::~CActiveXApp
  104. // ---------------------------------------------------------------------------------
  105. // Destructor
  106.  
  107. CActiveXApp::~CActiveXApp()
  108. {
  109. }
  110.  
  111.  
  112. // ---------------------------------------------------------------------------
  113. //        Ñ Initialize
  114. // ---------------------------------------------------------------------------
  115. //    Last chance to initialize Application before processing events
  116.  
  117. void CActiveXApp::Initialize()
  118. {
  119.     //    Start the mouse tracker
  120.     LMouseTracker *mouseTracker = new LMouseTracker;
  121.     mouseTracker->StartIdling();
  122. }
  123.  
  124.  
  125. // ---------------------------------------------------------------------------------
  126. //        Ñ CActiveXApp::StartUp
  127. // ---------------------------------------------------------------------------------
  128.  
  129. void
  130. CActiveXApp::StartUp()
  131. {
  132.     //    ÑActiveXÑ on startup bring up the default document type
  133.     ObeyCommand( cmd_DefaultDocument, nil );
  134. }
  135.  
  136.  
  137. // ---------------------------------------------------------------------------
  138. //        Ñ CActiveXApp::ObeyCommand
  139. // ---------------------------------------------------------------------------
  140. //    Respond to commands
  141.  
  142. Boolean
  143. CActiveXApp::ObeyCommand(
  144.     CommandT    inCommand,
  145.     void        *ioParam)
  146. {
  147.     Boolean        cmdHandled = true;
  148.  
  149.     switch (inCommand) {
  150.     
  151.         case cmd_NewSinglePane:
  152.             SendAECreateDocument();
  153.             break;
  154.         case cmd_NewMultiPane:
  155.         case cmd_NewMultiContext:
  156.             new CActiveXDocument( this, nil, inCommand );
  157.             break;
  158.             
  159.         default:
  160.             cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  161.             break;
  162.     }
  163.     
  164.     return cmdHandled;
  165. }
  166.  
  167.  
  168. // ---------------------------------------------------------------------------------
  169. //        Ñ CActiveXApp::FindCommandStatus
  170. // ---------------------------------------------------------------------------------
  171. //    set menu command status
  172.  
  173. void
  174. CActiveXApp::FindCommandStatus(
  175.     CommandT    inCommand,
  176.     Boolean        &outEnabled,
  177.     Boolean        &outUsesMark,
  178.     Char16        &outMark,
  179.     Str255        outName )
  180. {
  181.     switch ( inCommand ) {
  182.  
  183.         case cmd_NewSinglePane:
  184.         case cmd_NewMultiPane:
  185.         case cmd_NewMultiContext:
  186.         {
  187.             outEnabled = true;
  188.             break;
  189.         }
  190.  
  191.         case cmd_PageSetup:
  192.         {
  193.             // Short circuit the page setup command
  194.             // since this example doesn't print.
  195.             outEnabled = false;
  196.         }
  197.         break;
  198.  
  199.         default:
  200.         {
  201.             // Call inherited.
  202.             LDocApplication::FindCommandStatus( inCommand,
  203.                 outEnabled, outUsesMark, outMark, outName );
  204.         }
  205.         break;
  206.  
  207.     }
  208. }
  209.  
  210.  
  211. // ---------------------------------------------------------------------------------
  212. //        Ñ CActiveXApp::OpenDocument
  213. // ---------------------------------------------------------------------------------
  214. //    open a document from an FSSpec
  215.  
  216. void
  217. CActiveXApp::OpenDocument(
  218.     FSSpec    *inMacFSSpec )
  219. {
  220.     // ÑActiveXÑ create a new document using the file spec
  221.     new CActiveXDocument( this, inMacFSSpec, 0 );
  222. }
  223.  
  224.  
  225. // ---------------------------------------------------------------------------------
  226. //        Ñ CActiveXApp::MakeNewDocument
  227. // ---------------------------------------------------------------------------------
  228. //    make a new empty document
  229.  
  230. LModelObject *
  231. CActiveXApp::MakeNewDocument()
  232. {
  233.     // ÑActiveXÑ Make a new empty document of the default type
  234.     return new CActiveXDocument( this, nil, cmd_DefaultDocument );
  235. }
  236.  
  237.  
  238. // ---------------------------------------------------------------------------------
  239. //        Ñ CActiveXApp::ChooseDocument
  240. // ---------------------------------------------------------------------------------
  241. //    choose a document with standard file
  242.  
  243. void
  244. CActiveXApp::ChooseDocument()
  245. {
  246.     // Deactivate the desktop.
  247.     ::UDesktop::Deactivate();
  248.  
  249.     // Browse for a document.
  250.     SFTypeList            theTypeList = {'Actx'};
  251.     StandardFileReply    theReply;
  252.     ::StandardGetFile( nil, 1, theTypeList, &theReply );
  253.  
  254.     // Activate the desktop.
  255.     ::UDesktop::Activate();
  256.     
  257.     // Send an apple event to open the file.    
  258.     if ( theReply.sfGood ) SendAEOpenDoc( theReply.sfFile );
  259. }
  260.  
  261.  
  262.